<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="招待标题" prop="title" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="招待类型" prop="entertainTypeName" width="100"></el-table-column>
				<el-table-column label="用餐类型" prop="diningTypeName" width="100"></el-table-column>
				<el-table-column label="用餐人员" prop="userCount" width="100">
					<template #default="scope">
						{{scope.row.userCount}}/人
					</template>
				</el-table-column>
				<el-table-column label="接待时间" prop="entertainTime" width="150"></el-table-column>
				<el-table-column label="接待人" prop="userName" width="100"></el-table-column>
				<el-table-column label="备注说明" prop="remark" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="doApproval(scope.row, scope.$index)">审批</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import recordDetails from './../enter/details'
export default {
	name: 'Entertain For Approve',
	components: {
		scSelectFilter,
		recordDetails
	},
	data() {
		return {
			dialog: {
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "用餐类型",
					key: "diningType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "招待类型",
					key: "entertainType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				}
			],
			apiObj: this.$API.office.entertain.getEntertainListForApprove,
			selection: [],
			search: {
				date:'',
				diningType:'',
				entertainType:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getDiningType();
		this.getEntertainType();
	},
	methods: {
		async getDiningType()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'diningType'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getEntertainType()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'entertainType'});
			if (res.code == 200) {
				this.filterData[2].options=this.filterData[2].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//编辑
		doApproval(row) {
			this.$confirm('请您审批是否通过?', '提示', {
				distinguishCancelAndClose:true,
				confirmButtonText: '通过',
				cancelButtonText: '不通过',
				type: 'warning'
			}).then(async () => {
				var res = await this.$API.office.entertain.updateEntertain.post({recordId: row.recordId, status: "1"});
				if (res.code == 200) {
					this.$refs.table.refresh()
					this.$message.success(res.message)
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
			}).catch(async (action) => {
				if(action === 'cancel') {
					var res = await this.$API.office.entertain.updateEntertain.post({recordId: row.recordId, status: "0"});
					if (res.code == 200) {
						this.$refs.table.refresh()
						this.$message.success(res.message)
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			});
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open("setting").setData(row)
			})
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.diningType = data.diningType;
			this.search.entertainType = data.entertainType;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
